package com.example.hemin.fnb.ui.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.hemin.fnb.R;
import com.example.hemin.fnb.ui.bean.ShopBean;

import java.util.ArrayList;
import java.util.List;

public class ShopAdapters extends RecyclerView.Adapter<ShopAdapters.ViewHolders>{
    private List<ShopBean> beans = new ArrayList<>();
    private  Context context;
    public ShopAdapters(Context context,List<ShopBean> beans){
         this.context = context;
         this.beans = beans;
    }
    @NonNull
    @Override
    public ShopAdapters.ViewHolders onCreateViewHolder(@NonNull ViewGroup parent, int i) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.shop_activity, parent, false);

        DisplayMetrics metrics = context.getResources().getDisplayMetrics();
        int heightPixels = metrics.heightPixels;
        ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
        layoutParams.height=heightPixels/2;
        ViewHolders viewHolder = new ViewHolders(view);

//        int parentHeight= parent.getHeight();
//        parent.getWidth();
//        ViewGroup.LayoutParams layoutParams = viewHolder.itemView.getLayoutParams();
//        layoutParams.height = parentHeight/2;
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ShopAdapters.ViewHolders viewHolder, int i) {
                ShopBean bean = beans.get(i);
                viewHolder.t1.setText(bean.getTime());
                viewHolder.t2.setText(bean.getPice());
                viewHolder.t3.setText(bean.getPice());
    }

    @Override
    public int getItemCount() {
        return beans.size();
    }

    public class ViewHolders extends RecyclerView.ViewHolder {
        TextView t1,t2,t3;
        public ViewHolders(@NonNull View itemView) {
            super(itemView);
            t1 = itemView.findViewById(R.id.shop_time);
            t2 = itemView.findViewById(R.id.titl1);
            t3 = itemView.findViewById(R.id.title2);
        }
    }
}
